package com.ming.controller;

import com.ming.sevice.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:何元才
 * @Desc:
 * @data:2021-04-07 16:41
 */
@RestController
@RequestMapping("p/sms")
@Api(tags = "会员发短信管理接口")
public class SendSmsController {

    @Autowired
    private UserService userService;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * {phonenum: "15671659691", code: ""}
     *
     * @param map
     * @return
     */
    @PostMapping("send")
    @ApiOperation("发送短信验证吗")
    public ResponseEntity<String> sendSms(@RequestBody Map<String, String> map) {
        // 发短信也要记录数据库
        userService.send(map);
        return ResponseEntity.ok("发送成功，请稍后再手机查看");
    }

    @PostMapping("savePhone")
    @ApiOperation("保存手机号")
    public ResponseEntity<String> savePhone(@RequestBody Map<String, String> map){
        userService.savePhone(map);
        return ResponseEntity.ok("保存成功");
    }

}
